#include "CLoadSaveGame.h"
#include "CLoadMap.h"

LoadSaveGame::LoadSaveGame(string objectPath, string inforPath)
{
	_treePath="";
	_objecPath=objectPath;
	_inforPath=inforPath;

};

void LoadSaveGame::Load()
{
	// load general infor
	ifstream inforFile(_inforPath);
	if(inforFile.is_open())
	{
		// read file
		// level, score, life, money
		inforFile>>_data._level>>_data._score>>_data._life>>_data._money;

		// mario
		// pos, state
		float x, y;
		int state;
		int preState;
		inforFile>>x>>y>>state>>preState;
		_data._mario=new Mario(D3DXVECTOR2(x, y), (EMarioState)state,(EMarioState)preState);				
		inforFile.close();
	}	

	// load quadtree from file
	switch(_data._level)
	{
	case 1:
		_treePath = "MapMario\\lv1\\map.txt";
		break;
	case 2:
		_treePath = "MapMario\\lv2\\map.txt";
		break;
	case 3:
		_treePath = "MapMario\\lv3\\map.txt";
		break;
	case 0: 
		_treePath = "MapMario\\lvbonus\\map.txt";
		break;
	}
	_data._cloadMap =new CLoadMap(_objecPath, _treePath, true);
	_data._tree=new CQuadtree();
	_data._cloadMap->LoadToQuadtree(_data._tree);
};

SaveGameInfor LoadSaveGame::GetInfor()
{
	return _data;	
}